package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-14
 * Time: 12:01
 */
class Message<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}
public class Test4 {
    public static void func2(Message<? super Fruit> temp) {
        temp.setMessage(new Banana());
        temp.setMessage(new Apple());
        System.out.println(temp.getMessage());
    }

    public static void main(String[] args) {
        Message<Fruit> fruitMessage = new Message<>();
        Message<Food> foodMessage = new Message<>();
        foodMessage.setMessage(new Food());
        fruitMessage.setMessage(new Fruit());
        func2(foodMessage);
        func2(fruitMessage);
    }

    public static void func(Message<? extends Fruit> temp) {
        System.out.println(temp.getMessage());
    }
    public static void main4(String[] args) {
        Message<Apple> message = new Message<>();
        message.setMessage(new Apple());
        Message<Banana> message2 = new Message<>();
        message2.setMessage(new Banana());
        func(message);
        func(message2);
    }

    public static void main1(String[] args) {
        Message<String> message = new Message<>() ;
        message.setMessage("比特就业课欢迎您");
        fun(message);
        Message<Integer> message2 = new Message<>() ;
        message2.setMessage(122);
        fun(message);
    }
    public static void fun(Message<?> temp){
        //不能进行元素的修改
        System.out.println(temp.getMessage());
    }
//    public static void fun(demo.Message<String> temp){
//        System.out.println(temp.getMessage());
//    }
}